<script src="{{ getAssets }}js/amazeui.datatables.min.js?v={{ assets_version }}"></script>
<script src="{{ getAssets }}js/jquery.table2excel.min.js?v={{ assets_version }}"></script>
<script>
    var badreport_id = '{{ .m.Id }}';
    var tables = $('#dataTables').DataTable({
        "sAjaxSource": '{{ urlfor "BadreportController.BadreportView"}}'
        , "bLengthChange": false
        , "fnServerData": function (sSource, aoData, fnCallback) {
            var queryParams = checkQueryTableData(aoData);
            queryParams.badreport_id = Number(badreport_id);
            $.post(sSource, JSON.stringify(queryParams), function (resp) {
                isLoading = true;
                fnCallback(resp);
            }, 'json')
        }
        , columns: [
            {"data": "Id", "bSortable": false}
            ,{render: function (data, type, full, meta) {
                    var html = productGroupName(full.Inventory.Products);
                    html += '<div class="attr">';
                    html += goodsAttr(full.Inventory);
                    html += '</div>';
                    return html;
            },"bSortable": false}
            ,{"data": "badreport_reson", "bSortable": false}
            ,{"data": "badreport_num", "bSortable": false}
        ]
        , "serverSide": true
        , "bPaginate": false
        , "bFilter": false	//是否启动过滤、搜索功能
        , "bInfo": false //是否显示页脚信息，DataTables插件左下角显示记录数
        , "bProcessing": true //DataTables载入数据时，是否显示‘进度’提示
    });
    function goodsAttr(full) {
        var html = '';
        switch(full.Products.TypeId){
            case 10:
                html += '<span>'+ full.Snd.sph +'</span><span>'+ full.Snd.cyl +'</span>';
                break;
            case 20:
                html += '<span>'+ full.Snd.sph +'</span><span>'+ full.Snd.cyl +'</span>';
                html += '<span>批号：'+ full.Acceptance.lot_number +'</span><span>生产日期：'+ timetransDate(full.Acceptance.manufacture_date) +'</span><span>有效日期：'+ timetransDate(full.Acceptance.expiry_date) +'</span>';
                break;
            case 30:
                html += '<span>'+ full.Snd.model +'</span><span>'+ full.Snd.color +'</span><span>'+ full.Snd.genre +'</span>';
                break;
            case 40:
                html += '<span>'+ full.Snd.sph +'</span><span>'+ full.Snd.add +'</span>';
                break;
            case 41:
                html += '<span>'+ full.Snd.model +'</span><span>'+ full.Snd.color +'</span><span>'+ full.Snd.genre +'</span>';
                break;
            case 50:
                html += '<span>批号：'+ full.Acceptance.lot_number +'</span><span>生产日期：'+ timetransDate(full.Acceptance.manufacture_date) +'</span><span>有效日期：'+ timetransDate(full.Acceptance.expiry_date) +'</span>';
                break;
        }
        return html;
    }
	
	$('#cennelBtn').click(function(){
		layer.confirm('确定要驳回该报损单吗？', function(index){
			$.post('{{ urlfor "BadreportController.BadreportAuditing" }}', {'badreport_id':badreport_id,'status':'cennel'}, function(res){
			    if(res.code == 1) {
			        layer.alert(res.msg);return;
                }
			    location.reload();
			}, 'json');
			layer.close(index);
		});
		return false;
	});
	$('#yesBtn').click(function(){
		layer.confirm('确定要通过该报损单吗？', function(index){
			$.post('{{ urlfor "BadreportController.BadreportAuditing" }}', {'badreport_id':badreport_id,'status':'yes'}, function(res){
                if(res.code == 1) {
                    layer.alert(res.msg);return;
                }
                location.reload();
			}, 'json');
			layer.close(index);
		});
		return false;
	});
    var isLoading = false;
    $('#download').bind("click", function(){
        if(isLoading) {
            $("#dataTables").table2excel({

                exclude: ".noExl",

                name: "导出报损商品明细",

                filename: "报损商品明细",

                fileext: ".xls",

                exclude_img: false,

                exclude_links: false,

                exclude_inputs: false
            });
        } else {
            $("#searchsubmit").click();
            layer.msg("还没加载结束请耐心等待一下！");return false;
        }
        return false;
    });
</script>
